﻿using System;
using System.Windows;
using System.Windows.Controls;
using GameEngine.View.Components;
using GameEngine.Model.Data;
using GameEditor.View.Components;
using GameEngine.Clients.Silverlight.View.Components;

namespace SilverlightClientEditor.View.Components
{
    public partial class ThingPropertiesEditorUC : UserControl, IThingEditorMenuView<int>
    {
        //ItemEditorMenuUC creator = new ItemEditorMenuUC();
        //readonly ChildWindow childWnd;

        public ThingPropertiesEditorUC()
        {
            InitializeComponent();
            okButton.Tag = IThingEditorMenuViewConstants.ButtonTags.OK;
            cancelButton.Tag = IThingEditorMenuViewConstants.ButtonTags.CANCEL;
            //childWnd = new ChildWindow()
            //{
            //    Content = creator
            //};
            //creator.OnAddShapeClick += new Action<string, string, object>(delegate(string itemTypeName, string shapeType, object shapeProps)
            //{
            //    if(OnAddShapeClick!=null)
            //        OnAddShapeClick(itemTypeName, shapeType, shapeProps);
            //});
            //creator.OnRemoveShapeClick += new Action<string, string>(delegate(string itemTypeName, string shapeName)
            //{
            //    if(OnRemoveShapeClick!=null)
            //        OnRemoveShapeClick(itemTypeName, shapeName);
            //});
            //creator.OnCreateItemClick +=new Action<string>(delegate(string arg1){
            //    if (OnCreateItemClick != null)
            //        OnCreateItemClick(arg1);
            //    childWnd.Close();
            //});
            //itemTypeListBox.SelectionChanged += new SelectionChangedEventHandler(itemListBox_SelectionChanged);
        }

        public Point Position { 
            get { 
                return new Point(
                    double.Parse(PositionXTextBox.Text), 
                    double.Parse(PositionYTextBox.Text));
            }
            set {
                PositionXTextBox.Text = value.X.ToString();
                PositionYTextBox.Text = value.Y.ToString();
            }
        }
        public ThingTypeVOId Type { get; set; }
        public ThingVOId<int> Id { get; set; }
        public bool EnableControl
        {
            get
            {
                return this.IsEnabled;
            }
            set
            {
                this.IsEnabled = value;
            }
        }

        public event OnButtonClickHandler<IThingEditorMenuViewConstants.ButtonTags> OnExternalActionButtonClick;

        /*void itemListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0 && OnItemTypeClick != null)
                OnItemTypeClick(e.AddedItems[0] as string);
        }*/

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var button = (Button)sender;
            if (OnExternalActionButtonClick != null)
                OnExternalActionButtonClick((IThingEditorMenuViewConstants.ButtonTags)button.Tag);
            //if (sender.Equals(addButton))
            //{
            //    if(OnAddItemClick!=null)
            //        OnAddItemClick(itemListBox.SelectedItem as string);
            //}
            //else if (sender.Equals(createButton))
            //{
            //    if (OnNewItemClick != null)
            //        OnNewItemClick();
            //}
        }

        /*public void ShowCreateWindow() {
            childWnd.Show();
        }*/
        
        //#region ITileMapEditorMenuView Members

        //public event Action<string, string, object> OnAddShapeClick;
        //public event Action<string, string> OnRemoveShapeClick;
        //public event Action<string> OnCreateItemClick;
        //public event Action<string> OnAddItemClick;
        //public event Action OnNewItemClick;
        //public event Action<string> OnItemTypeClick;

        //public void AddShapeToList(string shape) {
        //    //creator.AddShapeToList(shape);
        //}

        //public void RemoveShapeFromList(string shape) {
        //    //creator.RemoveShapeFromList(shape);
        //}

        //public void RemoveAllShapesFromList() {
        //    //creator.RemoveAllShapes();
        //}

        //public void AddTypeToList(string type) {
        //    itemTypeListBox.Items.Add(type);
        //}

        //#endregion

        //public void SetItemEditorWorldView(WorldUC world)
        //{
        //    //creator.Initialize(world);
        //}

        //public event Action<string> OnCreateClick;

        //public event Action<string> OnEditClick;

        //public event Action<string> OnRemoveClick;

        //public event Action<IThingTypeVOId<int>> OnAddItemToWorldClick;

        ///*event Action<IThingTypeVOId<int>> IThingEditorMenuView<int>.OnItemTypeClick
        //{
        //    add { throw new NotImplementedException(); }
        //    remove { throw new NotImplementedException(); }
        //}*/

        //public event Action OnNewClick;
    }
}